<?php
require_once 'PHPExcel.php';
require_once 'PHPExcel/IOFactory.php';
require_once 'PHPExcel/Shared/Date.php';

//set_time_limit(0) ;

$xls_name = isset($_REQUEST['name'])?$_REQUEST['name']:'aa.xls';
//$xls_name = "15254125134958.xls";

$file_xls = "./../../images/upload/".$xls_name;
if (!file_exists($file_xls)) {
	exit("not found $file_xls.\n");
}

//$file_xls = "123.xls";


$filename = $file_xls;
$objReader = PHPExcel_IOFactory::createReaderForFile($filename);
//$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($filename);
$data['sheetsinfo'] = $objReader->listWorksheetInfo($filename);

$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
//$columnCount = PHPExcel_Cell::columnIndexFromString( $worksheet->getHighestColumn() );
$rowCount = $worksheet->getHighestRow();

if($rowCount>2000){
	echo 0;
	exit;
}

$columnCount = 14;
$dataset = array();
for($row = 1; $row <= $rowCount; $row++){
	//0123456789
	//ABCDEFGHIJ
    if($row>1){
		for($column=0; $column<$columnCount; $column++){
			$cell = $worksheet->getCellByColumnAndRow($column,$row);
			$cellstyleformat = $worksheet->getStyle($cell->getCoordinate())->getNumberFormat();
			$formatcode = $cellstyleformat->getFormatCode();
			
			$f_value = $cell->getFormattedValue();
			//$value   = $cell->getValue();		
			//$p_value = PHPExcel_Shared_Date::ExcelToPHP($value);	
			
			if($column==0 or $column==1){
				if(empty($f_value)){
					break;
				}else{
					$dataset[] = $f_value;
				}				
			}else{
				$dataset[] = $f_value;
			}
		}
		
	}
}


//重组行
$row_sum = ceil(count($dataset)/14);
$arr = array();
for($i=1;$i<=$row_sum;$i++){
	$mline = array();
	foreach($dataset as $k=>$v){	
		if($k>=($i*14-14) && $k<($i*14)){
			$mline[] = $v;
		}
	}
	$arr[] = $mline;
}

//var_dump($arr);
echo json_encode($arr);
exit;







